package com.yoome.easyrpc.biz.registry.zookeeper;

import com.yoome.easyrpc.biz.registry.ServiceRegistry;
import com.yoome.easyrpc.common.consts.Symbols;
import com.yoome.easyrpc.common.utils.CuratorUtil;
import org.apache.curator.framework.CuratorFramework;
import org.springframework.stereotype.Component;

import java.net.InetSocketAddress;

@Component
public class ZkServiceRegistry implements ServiceRegistry {
    @Override
    public void registerService(String serviceName, InetSocketAddress socketAddress) {
        StringBuffer pathBuffer = new StringBuffer(CuratorUtil.ZK_ROOT_PATH);
        String path = pathBuffer.append(Symbols.SLASH)
                .append(serviceName)
                .append(socketAddress)
                .toString();
        CuratorFramework client = CuratorUtil.getClient();
        CuratorUtil.createPersistentNode(client, path);
    }
}
